package com.ydd.controller.admin;

import com.ydd.dto.MenuDTO;
import com.ydd.entity.SysMenu;
import com.ydd.result.Result;
import com.ydd.service.SysMenuService;
import com.ydd.vo.SysmenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:42
 */
@Api(tags = "权限管理-菜单管理")
@RestController
@RequestMapping("/admin/sys_menu")
@Slf4j
public class SysMenuController {
    @Autowired
    SysMenuService sysMenuService;

    @PostMapping("/update")
    @ApiOperation("菜单修改")
    public Result updateMenu(@RequestBody MenuDTO sysMenu){
        sysMenuService.updateMenu(sysMenu);
        return Result.success();
    }

    @GetMapping("/del")
    @ApiOperation("菜单删除")
    public Result deleteMenu(String id){
        sysMenuService.deleteMenu(id);
        return Result.success();
    }

    @GetMapping("/allData")
    @ApiOperation("查询所有菜单")
    public Result<List<SysmenuVO>> allMenuData(){
        Long pId=0L;
        List<SysmenuVO> sysmenuall= sysMenuService.allData(pId);
        return Result.success(sysmenuall);
    }

    @PostMapping("/add")
    @ApiOperation("新增菜单")
    public Result addMenu(@RequestBody MenuDTO sysMenu){
        sysMenuService.addMenu(sysMenu);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    @ApiOperation("菜单详情")
    public Result<SysmenuVO> rowInfo(String id){
        Integer Id = Integer.valueOf(id);
        SysmenuVO sysMenu=sysMenuService.getMenuById(Id);
        return Result.success(sysMenu);
    }
}
